package com.tr.rentcar.controller.houtai.usermanage;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.common.StringUtils;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.dao.UserDao;
import com.tr.rentcar.model.dao.UserRecordDao;
import com.tr.rentcar.model.bean.UserRecord;
@WebServlet("/moeycharge")
public class moeychargeController extends HttpServlet {
	User User=new User();
	UserDao UserDao=new UserDao();
	UserRecordDao UserRecordDao=new UserRecordDao();
	UserRecord UserRecord=new UserRecord();
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		try {
		String chongmoney=req.getParameter("chongmoney");
		String tel2=req.getParameter("tel2");
		User user=UserDao.findByTel(tel2);
		if(user==null){
			req.setAttribute("error", "查无此人");
		}
		System.out.println("ok3");
		UserRecord.setuId(Integer.parseInt(user.getUid()+""));
		UserRecord.setUrWay("充值");
		UserRecord.setUrMoney(Double.valueOf(chongmoney));
		UserRecord.setUrdoWay("管理员");
		UserRecord.setUrName("sb");
		if(UserRecordDao.save(UserRecord))
		{user.setUmoney(user.getUmoney()+UserRecord.getUrMoney());
		
		UserDao.xgmoney(user.getUmoney(),user.getUid());
		};
		
		
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		//req.getRequestDispatcher("/WEB-INF/jsp/houtai_userManage.jsp").forward(req, resp);
		resp.sendRedirect(req.getContextPath()+"/houtaiuser");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("dsfdsf");
		doGet(req, resp);
	}
	
	
	

}
